import re
import json

def up_tag_get(text):

    up_tag_info_gender = ''

    up_tag_info_age = ''

    up_tag_location = ''

    up_tag_profession = ''

    up_tag_college = ''

    try:
        # 使用正则表达式查找匹配
        matches = re.findall(r'"tags":\[.*?\]', text, re.DOTALL)
        list_dic = json.loads(matches[0].replace(""""tags":""", ""))
    except:
        print('匹配错误!')
        return [up_tag_info_gender, up_tag_info_age, up_tag_location, up_tag_profession, up_tag_college]

    for item in list_dic:
        # info
        print(item)
        if item.get('tagType') == 'info':
            if item.get('name'):
                up_tag_info_age = item.get('name')
            if item.get('icon'):
                if 'female' in item.get('icon'):
                    up_tag_info_gender = 'female'
                else:
                    up_tag_info_gender = 'male'
        # tagType
        if item.get('tagType') == 'location':
            if item.get('name'):
                up_tag_location = item.get('name')
        # profession
        if item.get('tagType') == 'profession':
            if item.get('name'):
                print(item.get('name'))
                up_tag_profession = up_tag_profession + item.get('name') + ','
                print(up_tag_profession)
        # college
        if item.get('tagType') == 'college':
            if item.get('name'):
                print(item.get('name'))
                up_tag_college = item.get('name')
                print(up_tag_college)        

    return [up_tag_info_gender, up_tag_info_age, up_tag_location, up_tag_profession[:-1], up_tag_college]



def get_some_up_data(text, wanna_type):
    #text = """scdn.com\u002Favatar\u002F1000g2jo2qi1a6amk40005of5gc4k15hl290ajrg?imageView2\u002F2\u002Fw\u002F360\u002Fformat\u002Fwebp","redId":"hhyizss618","gender":0},"interactions":[{"type":"follows","name":"关注","count":"16"},{"type":"fans","name":"粉丝","count":"36823"},{"name":"获赞与收藏","count":"307541","type":"interaction"}]"""

    # 使用正则表达式查找匹配
    matches = re.findall(r'\{[^{}]*"name":"'+wanna_type+r'[^{}]*\}', text)


    return json.loads(matches[0]).get('count')